﻿using MediatR;
using Microsoft.EntityFrameworkCore;
using Traceability_Management.Domain;
using Traceability_Management.ErrorCode;
using Traceability_Management.Infrastructure.Interfaces;
using Traceability_Management.Read.Api.Application.Command.RabitsWay;

namespace Traceability_Management.Read.Api.Application.CommandHandler.RabitsWay
{
    public class FirstRabitsCommandHandler : IRequestHandler<FirstRabitsCommand, ApiResult<Rabits>>
    {
        IBaseReponsitory<Rabits> Rabits;

        public FirstRabitsCommandHandler(IBaseReponsitory<Rabits> Rabits)
        {
            this.Rabits = Rabits;
        }

        public async Task<ApiResult<Rabits>> Handle(FirstRabitsCommand request, CancellationToken cancellationToken)
        {
            var list =await Rabits.GetQuery().FirstOrDefaultAsync(c=>c.Rabit_Batch==request.Batch);
            return new ApiResult<Rabits> 
            {
                Code=ApiEnum.Success,
                Message="填充成功",
                Data=list
            };
        }
    }
}
